home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 128_01 / roff41.c < prev    next >
Text File  |  1985-03-09  |  7KB  |  210 lines

  1. /********************************************************/
  2. /*                            */
  3. /*            ROFF4, Version 1.60            */
  4. /*                            */
  5. /*(C) 1983,4 by Ernest E. Bergmann            */
  6. /*        Physics, Building #16            */
  7. /*        Lehigh Univerisity            */
  8. /*        Bethlehem, Pa. 18015            */
  9. /*                            */
  10. /* Permission is hereby granted for all commercial and    */
  11. /* non-commercial reproduction and distribution of this    */
  12. /* material provided this notice is included.        */
  13. /*                            */
  14. /********************************************************/
  15. /*Jan 8, 1984*/
  16. #include "roff4.h"
  17. /**********************************************************
  18. Removes white-space characters at start of string.
  19. ***********************************************************/
  20. skip_blanks ( string )
  21. char *string;    /* cursor to original string */
  22. {char *p;    /* cursor to 'final' string */
  23. for(p=string;*string==BLANK||*string==TAB||*string==NEWLINE;
  24.     string++);
  25. while(*(p++) = *(string++));
  26. }
  27. /*************************************************************/
  28. int comtyp (line)
  29. char *line;
  30. {char let1, let2;
  31. let1 = toupper( line[1] );
  32. let2 = toupper( line[2] );
  33.  
  34. if ( let1==COMMAND )        return( IG );
  35. if ( let1=='I' && let2=='G')    return( IG );
  36. if ( let1=='F' && let2=='I')    return( FI );
  37. if ( let1=='F' && let2=='O')    return( FO );
  38. if ( let1=='T' && let2=='I')    return( TI );
  39. if ( let1=='B' && let2=='P')    return( BP );
  40. if ( let1=='B' && let2=='R')    return( BR );
  41. if ( let1=='C' && let2=='E')    return( CE );
  42. if ( let1=='H' && let2=='E')    return( HE );
  43. if ( let1=='I' && let2=='N')    return( IN );
  44. if ( let1=='L' && let2=='S')    return( LS );
  45. if ( let1=='N' && let2=='F')    return( NF );
  46. if ( let1=='P' && let2=='L')    return( PL );
  47. if ( let1=='R' && let2=='M')    return( RM );
  48. if ( let1=='S' && let2=='P')    return( SP );
  49. if ( let1=='S' && let2=='T')    return( ST );
  50. if ( let1=='N' && let2=='E')    return( NE );
  51. if ( let1=='F' && let2=='F')    return( FF );
  52. if ( let1=='S' && let2=='C')    return( SC );
  53. if ( let1=='O' && let2=='W')    return( OW );
  54. if ( let1=='T' && let2=='S')    return( TS );
  55. if ( let1=='O' && let2=='H')    return( OH );
  56. if ( let1=='O' && let2=='F')    return( OF );
  57. if ( let1=='E' && let2=='H')    return( EH );
  58. if ( let1=='E' && let2=='F')    return( EF );
  59. if ( let1=='A' && let2=='B')    return( AB );
  60. if ( let1=='D' && let2=='B')    return( DB );
  61. if ( let1=='T' && let2=='C')    return( TC );
  62. if ( let1=='T' && let2=='R')    return( TR );
  63. if ( let1=='C' && let2=='F')    return( CF );
  64. if ( let1=='I' && let2=='C')    return( IC );
  65. if ( let1=='O' && let2=='U')    return( OU );
  66. if ( let1=='J' && let2=='U')    return( JU );
  67. if ( let1=='N' && let2=='J')    return( NJ );
  68. if ( let1=='F' && let2=='R')    return( FR );
  69. if ( let1=='W' && let2=='H')    return( WH );
  70. if ( let1=='E' && let2=='M')    return( EM );
  71. if ( let1=='D' && let2=='M')    return( DM );
  72. if ( let1=='D' && let2=='S')    return( DS );
  73. if ( let1=='R' && let2=='G')    return( RG );
  74. if ( let1=='D' && let2=='I')    return( DI );
  75. if ( let1=='E' && let2=='D')    return( ED );
  76. if ( let1=='S' && let2=='O')    return( SO );
  77. if ( let1=='P' && let2=='C')    return( PC );
  78. if ( let1=='S' && let2=='A')    return( SA );
  79. if ( let1=='B' && let2=='J')    return( BJ );
  80.  
  81. if ( let1=='M')
  82.       { if (let2=='1')        return( M1 );
  83.     if (let2=='2')        return( M2 );
  84.     if (let2=='3')        return( M3 );
  85.     if (let2=='4')        return( M4 );
  86.       }
  87. return( UNKNOWN );        /* no match */
  88. }
  89. /*************************************************************
  90. gets the number ( if any ) associated with any command 
  91. *************************************************************/
  92. int get_val ( line, typ )
  93. char *line, *typ;
  94. {int i;
  95. char local[ MAXLINE ];
  96. strcpy (local, line);    /* local copy */
  97. /* skip over the command line */
  98. for(i=1; local[i]!=' '&&local[i]!='\t'&&local[i]!='\n' ;i++);
  99.  
  100. skip_blanks (&local[i]);    /* find the number */
  101. *typ = local[i];    /* relative or absolute */
  102. if ( *typ=='+' || *typ=='-' )    i++;
  103. else if ( !isdigit( *typ ) )    return( NO_VAL );
  104. return ( atoi( &local[i] ));
  105. }
  106. /*************************************************************
  107.  sets a global parameter like SPVAL, PAGESTOP, etc.
  108.  Also checks that the new value is within the range of that 
  109.  parameter.  Assigns the default for that parameter if no value
  110.   is specified.
  111. *************************************************************/
  112. set ( param, val, arg_typ, defval, minval, maxval )
  113. int *param, val, defval, minval, maxval;
  114. char arg_typ;
  115. {if(val==NO_VAL) *param = defval;    /* defaulted */
  116. else if(arg_typ == '+') *param += val;    /* relative + */
  117. else if(arg_typ == '-')    *param -= val;    /* relative - */
  118. else    *param = val;            /* absolute */
  119. *param = min (*param,maxval);
  120. *param = max (*param, minval);
  121. if DEBUG fprintf(STDERR,"\tSET *param = %d\n", *param);
  122. }
  123. /*************************************************************
  124.     end current filled line 
  125. **************************************************************/
  126. brk()
  127. {int l;
  128. if DEBUG fprintf(STDERR,"brk: OUTBUF=<%s>\n", OUTBUF);
  129. if (OUTPOS) put(OUTBUF);
  130. OUTW=OUTPOS=OUTTOP=OUTBOT=OUTWRDS = 0;
  131. OUTBUF[0] = '\0';
  132. }
  133.  
  134. /**************************************************/
  135. initxu()    /*initialize underline,overstrike variables*/
  136. {    XCOL=UCOL=-1;
  137.     setmem(&XBUF,LSZ,' ');
  138.     setmem(&UBUF,LSZ,' ');
  139. }
  140. /****************************************/
  141. need(n)    /*test for space before footer*/
  142. int n;    /*whole lines*/
  143. {if (( VLINENO>=(BOTTOM-n) ) && (BOTTOM>=VLINENO) )
  144.     {space(HUGE); NEWPAG= ++CURPAG;
  145.     }
  146. }
  147. /****************************************/
  148. /*from stdlib1.c, with minor mods*/
  149.  
  150. free(ap)
  151. struct _header *ap;
  152. {
  153.     struct _header *p, *q;
  154.     p = ap - 1;    /* No need for the cast when "ap" is a struct ptr */
  155.  
  156.     for (q = _allocp; !(p > q && p < q -> _ptr); q = q -> _ptr)
  157.         if (q >= q -> _ptr && (p > q || p < q -> _ptr))
  158.             break;
  159.     if (p + p -> _size == q -> _ptr) {
  160.         p -> _size += q -> _ptr -> _size;
  161.         p -> _ptr = q -> _ptr -> _ptr;
  162.      }
  163.     else p -> _ptr = q -> _ptr;
  164.  
  165.     if (q + q -> _size == p) {
  166.         q -> _size += p -> _size;
  167.         q -> _ptr = p -> _ptr;
  168.      }
  169.     else q -> _ptr = p;
  170.  
  171.     _allocp = q;
  172. }
  173. /******************************************/
  174. char *alloc(nbytes)
  175. unsigned nbytes;
  176. {
  177.     struct _header *p, *q, *cp;
  178.     int nunits; 
  179.     nunits = 1 + (nbytes + (sizeof (_base) - 1)) / sizeof (_base);
  180.     if ((q = _allocp) == NULL) {
  181.         _base._ptr = _allocp = q = &_base;
  182.         _base._size = 0;
  183.      }
  184.     for (p = q -> _ptr; ; q = p, p = p -> _ptr) {
  185.         if (p -> _size >= nunits) {
  186.             if (p -> _size == nunits)
  187.                 q -> _ptr = p -> _ptr;
  188.             else {
  189.                 p -> _size -= nunits;
  190.                 p += p -> _size;
  191.                 p -> _size = nunits;
  192.              }
  193.             _allocp = q;
  194.             return p + 1;
  195.          }
  196.         if (p == _allocp) {
  197.             if ((cp = sbrk(nunits * sizeof (_base))) == ERROR)
  198.                 {fprintf(STDERR,"\nCan't Allocate more buffer space.");
  199.                 return NULL;
  200.                 }
  201.             cp -> _size = nunits; 
  202.             free(cp+1);    /* remember: pointer arithmetic! */
  203.             p = _allocp;
  204.         }
  205.      }
  206. }
  207.  -> _ptr -> _ptr;
  208.      }
  209.     else p -> _ptr = q -> _ptr;
  210.